<?
	require ('../businessObjects/accountableTransaction.php');
		
?>
<script language="javascript" src="js/jquery.jCombo.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){	   
/*Apply default button style. */		
		$('#btnSubmit').button();
		$('.gridButton').button();
		$( "#txtDate" ).datepicker();
/*Data load*/
	$("#lstEnterprise").jCombo({url: "getData.php?opt=ENT" });
	$("#lstEmployee").jCombo({url: "getData.php?opt=EMP&id=",parent: "#lstEnterprise" });
	$("#lstCategory").jCombo({url: "getData.php?opt=PEC&id=",parent: "#lstEnterprise" });
	$("#lstChildCategory").jCombo({url: "getData.php?opt=CEC&id=",parent: "#lstCategory" });
/*Form validation*/
		jQuery.validator.addMethod("SelectRequired", function(value, element, params) 
		{return params != value}, "Please choose one option");		
		$('#form1').validate({
			rules:{
				txtDate: {required:true, date:true}, 
				txtIncomeAmountGTQ: {required:true, number:true}, 
				txtIncomeAmountUSD: {number:true}, 
				txtExchangeRate: {number:true}, 
				txtTrackingNotes: {required:true},
				lstEnterprise: {SelectRequired : "default"},
				lstEmployee: {SelectRequired : "default"},
				lstCategory: {SelectRequired : "default"},
				lstChildCategory: {SelectRequired : "default"}				
			}, 
			messages: {
				txtDate: {required:'Please enter a date', date:'Please a date in format mm/dd/yyyy'}, 
				txtIncomeAmountGTQ: {required:'Please enter an amount', number:'Please enter a decimal number'}, 
				txtIncomeAmountUSD: {number:'Please enter an amount'}, 
				txtExchangeRate: {number:'Please enter an Exchange Rate'}, 
				txtTrackingNotes: {required:'Please enter Tracking Notes'}
			}
		});		
  });
</script>
<form id="form1" action="?<?=$_SERVER['QUERY_STRING']?>" method="post" enctype="multipart/form-data">
<div class="workspace_panel">
<div class="workspace_panel_row">
	<div class="workspace_panel_cell">
		<div style="display:table; width:100%;">
			<div style="display:table-row">
				<div style="display:table-cell; width:20%;"><h1>Add and Expense</h1></div>
				<div style="display:table-cell; text-align:right;">
					<a href="<?=$go_back_search?>" class="gridButton">Go Back </a>				
				</div>
			</div>
		</div>			
	</div>	
</div>
<?php
	if ($_POST['hddSeed'] == 'seed') {
		$obj = new sysFunctions();
		$fileName = $obj->uploadFile($_FILES['srcFile']);	
		$expense = new expense();
		$expense->addExpenses($_POST['lstEnterprise'], 
							date("Y-m-d",strtotime($_POST['txtDate'])),
							$_POST['txtIncomeAmountGTQ'], 
							$_POST['txtIncomeAmountUSD'],
							$_POST['txtExchangeRate'],
							$_POST['lstChildCategory'],
							$_POST['txtTrackingNotes'],
							$_SESSION['username'], $_POST['lstEmployee'],$fileName);
		$_dlg_Print_Message = $expense->message();
		include ('dialogMessages.php');
	}
?>
<div class="workspace_panel_row">	
	<div class="workspace_panel_cell">
		<div class="frmContainer" style="width:50%">
				<div class="frmRow">
					<div class="frmLabelCell">Enterprise</div>
					<div class="frmContentCell">
						<select name="lstEnterprise" id="lstEnterprise" class="controlListBox">														
						</select>  </div>
				</div>
				<div class="frmRow">
					<div class="frmLabelCell">Category</div>
					<div class="frmContentCell">
					<select name="lstCategory" id="lstCategory" class="controlListBox"></select> 
					<select name="lstChildCategory" id="lstChildCategory" class="controlListBox"></select> 
					</div>
				</div>
				<div class="frmRow">
					<div class="frmLabelCell">Costed by</div>
					<div class="frmContentCell">
						<select name="lstEmployee" id="lstEmployee" class="controlListBox">														
						</select>  
					</div>
				</div>
				<div class="frmRow">
					<div class="frmLabelCell">Date (mm/dd/yyyy)</div>
					<div class="frmContentCell"><input type="textbox" class="controlTextBoxDefault" id="txtDate" name="txtDate" value=""/></div>
				</div>
				<div class="frmRow">
					<div class="frmLabelCell">Amount GTQ</div>
					<div class="frmContentCell"><input type="textbox" class="controlTextBoxDefault" id="txtIncomeAmountGTQ" name="txtIncomeAmountGTQ"/> </div>
				</div>
				<div class="frmRow">
					<div class="frmLabelCell">Amount USD</div>
					<div class="frmContentCell"><input type="textbox" class="controlTextBoxDefault" id="txtIncomeAmountUSD" name="txtIncomeAmountUSD"/> </div>
				</div>
				<div class="frmRow">
					<div class="frmLabelCell">Exchange Rate USD / GTQ</div>
					<div class="frmContentCell"><input type="textbox" class="controlTextBoxDefault" id="txtExchangeRate" name="txtExchangeRate"/> </div>
				</div>				
				<div class="frmRow">
					<div class="frmLabelCell">Tracking Notes</div>
					<div class="frmContentCell"><input type="textbox" class="controlTextBoxDefault" id="txtTrackingNotes" name="txtTrackingNotes"/> </div>
				</div>
				<div class="frmRow">
					<div class="frmLabelCell">Attach a file</div>
					<div class="frmContentCell"><input type="file" class="controlTextBoxDefault" id="srcFile" name="srcFile"/> </div>
				</div>				
		</div>
	</div>
</div>
<div class="workspace_panel_row">
	<div class="workspace_panel_cell">
	<input type="hidden" id="hddSeed" name="hddSeed" value="seed" />
	<input type="submit" id="btnSubmit" name="btnSubmit" value ="Save" /></div>
</div>
</div>
</form>